package com.lyf.scm.admin.domain.remote.network.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.admin.api.dto.DateLabelDTO;
import com.lyf.scm.admin.domain.remote.network.NetworkRemote;
import com.lyf.scm.admin.domain.remote.network.dto.SearchSourceToCQueryDTO;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * description
 *
 * @author wangchlei
 * @date 2020/08/14
 */
@Service
@Slf4j
public class NetworkFacade {
    @Resource
    private NetworkRemote networkRemote;

    /**
     * 根据当前日期获取前三周后十四周公立节假日（对计划接口）
     *
     * @param startDate
     * @return {@link List<DateLabelDTO>}
     **/
    public List<DateLabelDTO> getDateLabels(Date startDate) {
        log.info("根据当前日期获取前三周后十四周公立节假日：Date：{}", startDate);
        Response<List<DateLabelDTO>> response = networkRemote.getDateLabels(startDate);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * TOC寻仓
     * @param queryToCList
     * @return
     */
    public List<SearchSourceToCQueryDTO> searchToCSource(List<SearchSourceToCQueryDTO> queryToCList) {
        log.info("TOC寻仓入参:queryToCList:{}", JSON.toJSONString(queryToCList));
        Response<List<SearchSourceToCQueryDTO>> response = networkRemote.searchToCSource(queryToCList);
        log.info("调组网寻仓返回数据:{}", response);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2009.getCode(),ResponseMsg.EXCEPTION_2009.getMsg());
        }
        return response.getData();
    }
}
